package bb.lanxing.databinding.utils;

import gov.nist.core.Separators;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class DateUtil {
    public static SimpleDateFormat format0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
    public static SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
    public static SimpleDateFormat format2 = new SimpleDateFormat("H:mm:ss", Locale.getDefault());
    public static SimpleDateFormat format3 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
    public static SimpleDateFormat format4 = new SimpleDateFormat("hh:mm", Locale.getDefault());
    public static SimpleDateFormat format5 = new SimpleDateFormat("mm:ss", Locale.getDefault());
    public static SimpleDateFormat format6 = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
    public static SimpleDateFormat format8 = new SimpleDateFormat("MM-dd HH:mm", Locale.getDefault());
    public static SimpleDateFormat format10 = new SimpleDateFormat("MM月dd日 HH:mm", Locale.getDefault());
    public static SimpleDateFormat format11 = new SimpleDateFormat("yyyy/MM/dd", Locale.getDefault());
    public static SimpleDateFormat format12 = new SimpleDateFormat("yyyy.MM.dd", Locale.getDefault());
    public static SimpleDateFormat format13 = new SimpleDateFormat("yyyy年MM月dd日", Locale.getDefault());
    public static SimpleDateFormat format14 = new SimpleDateFormat("yy/MM/dd", Locale.getDefault());
    public static SimpleDateFormat format15 = new SimpleDateFormat("MM-dd", Locale.getDefault());
    public static SimpleDateFormat format16 = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault());
    public static TimeZone timeZone = TimeZone.getTimeZone("GMT+8");

    public static String format(long j) {
        return format(j, 0);
    }

    public static String format(long j, int i) {
        switch (i) {
            case 0:
                return format0.format(new Date(j));
            case 1:
                return format1.format(new Date(j));
            case 2:
                return getHMS(j);
            case 3:
                return format3.format(new Date(j));
            case 4:
                return getHM(j);
            case 5:
                return format5.format(new Date(j));
            case 6:
                return format6.format(new Date(j));
            case 7:
                return format2.format(new Date(j));
            case 8:
                return format8.format(new Date(j));
            case 9:
                return format0.format(new Date(j + timeZone.getOffset(0L)));
            case 10:
                return format10.format(new Date(j));
            case 11:
                return format11.format(new Date(j));
            case 12:
                return format12.format(new Date(j));
            case 13:
                return format6.format(new Date(j + timeZone.getOffset(0L)));
            case 14:
                return format13.format(new Date(j));
            case 15:
                return format14.format(new Date(j));
            case 16:
                return format15.format(new Date(j));
            default:
                return format0.format(new Date(j));
        }
    }

    private static String getHMS(long j) {
        long j2 = j / 1000;
        long j3 = j2 % 60;
        long j4 = j2 / 60;
        long j5 = j4 % 60;
        long j6 = j4 / 60;
        StringBuilder sb = new StringBuilder();
        if (j6 >= 10) {
            sb.append(j6);
        } else if (j6 > 0) {
            sb.append("0");
            sb.append(j6);
        } else {
            sb.append("00");
        }
        sb.append(Separators.COLON);
        if (j5 < 10) {
            sb.append(0);
            sb.append(j5);
        } else {
            sb.append(j5);
        }
        sb.append(Separators.COLON);
        if (j3 < 10) {
            sb.append(0);
            sb.append(j3);
        } else {
            sb.append(j3);
        }
        return sb.toString();
    }

    private static String getHM(long j) {
        long j2 = (j / 1000) / 60;
        long j3 = j2 % 60;
        long j4 = j2 / 60;
        StringBuilder sb = new StringBuilder();
        if (j4 >= 10) {
            sb.append(j4);
        } else if (j4 > 0) {
            sb.append(0);
            sb.append(j4);
        } else {
            sb.append("00");
        }
        sb.append(Separators.COLON);
        if (j3 < 10) {
            sb.append(0);
            sb.append(j3);
        } else {
            sb.append(j3);
        }
        return sb.toString();
    }

    public static long parse(String str) {
        return parse(str, 0);
    }

    public static long parse(String str, int i) {
        try {
            if (i == 0) {
                return format0.parse(str).getTime();
            }
            if (i == 1) {
                return format1.parse(str).getTime();
            }
            if (i == 2) {
                return format2.parse(str).getTime();
            }
            if (i == 3) {
                return format3.parse(str).getTime();
            }
            if (i == 16) {
                return format16.parse(str).getTime();
            }
            return format0.parse(str).getTime();
        } catch (Exception e) {
            e.printStackTrace();
            return 0L;
        }
    }

    public static long getMonthTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(calendar.get(1), calendar.get(2), 1, 0, 0, 0);
        return calendar.getTime().getTime();
    }

    public static int getThisMonth() {
        return Calendar.getInstance().get(2);
    }

    public static String getAgoTimeString(Date date) {
        Date date2 = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        long time = (date2.getTime() - calendar.getTime().getTime()) / 1000;
        long j = 1;
        int i = (time > 60L ? 1 : (time == 60L ? 0 : -1));
        if (i < 0) {
            if (time <= 0) {
                time = 1;
            }
            return time + "秒前";
        } else if (i >= 0 && time < 3600) {
            long j2 = time / 60;
            if (j2 > 0) {
                j = j2;
            }
            return j + "分钟前";
        } else if (time >= 3600 && time < 86400) {
            long j3 = time / 3600;
            if (j3 > 0) {
                j = j3;
            }
            return j + "小时前";
        } else if (time < 86400 || time >= 604800) {
            if (time >= 604800 && time < 8640000) {
                return format8.format(date);
            }
            return format6.format(date);
        } else {
            long j4 = time / 86400;
            if (j4 > 0) {
                j = j4;
            }
            return j + "天前";
        }
    }

    public static String formatTime(long j) {
        if (j < 60) {
            return j + "秒";
        }
        int i = (int) (j / 60);
        if (i < 60) {
            return i + "分种";
        }
        int i2 = i / 60;
        if (i2 < 24) {
            return i2 + "小时";
        }
        return (i2 / 24) + "天";
    }

    public static boolean isSameDay(long j, long j2) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(j);
        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTimeInMillis(j2);
        return calendar.get(1) == calendar2.get(1) && calendar.get(2) == calendar2.get(2) && calendar.get(5) == calendar2.get(5);
    }
}
